home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr42 / smixc111.zip / MIXTEST.C < prev    next >
C/C++ Source or Header  |  1995-02-15  |  4KB  |  190 lines

  1. /*      SMIXC is Copyright 1995 by Ethan Brodsky.  All rights reserved      */
  2.  
  3. /* ██ MIXTEST.C ███████████████████████████████████████████████████████████ */
  4.  
  5. #include <conio.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <time.h>
  9.  
  10. #include "detect.h"
  11. #include "smix.h"
  12.  
  13. #define ON  1
  14. #define OFF 0
  15.  
  16. #define TRUE  1
  17. #define FALSE 0
  18.  
  19. #define SHAREDEMB    /* Undefine this to store all sounds in separate EMBs */
  20. #define NUMSOUNDS 6  /* Change this if you want to add more sounds         */
  21.  
  22. char *soundfile[NUMSOUNDS] =
  23.   {
  24.     "JET.RAW",
  25.     "GUN.RAW",
  26.     "CRASH.RAW",
  27.     "CANNON.RAW",
  28.     "LASER.RAW",
  29.     "GLASS.RAW"
  30.   };
  31.  
  32. int baseio, irq, dma, dma16;
  33.  
  34. SOUND *sound[NUMSOUNDS];
  35.  
  36. int  stop;
  37.  
  38. long counter;
  39.  
  40. char inkey;
  41. int  num;
  42. int  temp;
  43.  
  44. void ourexitproc(void)
  45.   {
  46.     int i;
  47.  
  48.     for (i=0; i < NUMSOUNDS; ++i)
  49.       if (sound[i] != NULL) free_sound(sound+i);
  50. #ifdef SHAREDEMB
  51.     shutdown_sharing();
  52. #endif
  53.   }
  54.  
  55. void init(void)
  56.   {
  57.     int i;
  58.  
  59.     randomize();
  60.  
  61.     printf("-------------------------------------------\n");
  62.     printf("Sound Mixing Library v1.11 by Ethan Brodsky\n");
  63.     if (!detect_settings(&baseio, &irq, &dma, &dma16))
  64.       {
  65.         printf("ERROR:  Invalid or non-existant BLASTER environment variable!\n");
  66.         exit(EXIT_FAILURE);
  67.       }
  68.     else
  69.       {
  70.         if (!init_sb(baseio, irq, dma, dma16))
  71.           {
  72.             printf("ERROR:  Error initializing sound card!\n");
  73.             exit(EXIT_FAILURE);
  74.           }
  75.       }
  76.  
  77.     printf("BaseIO=%Xh     IRQ%u     DMA8=%u     DMA16=%u\n", baseio, irq, dma, dma16);
  78.  
  79.     printf("DSP version %.2f:  ", dspversion);
  80.     if (sixteenbit)
  81.       printf("16-bit, ");
  82.     else
  83.       printf("8-bit, ");
  84.     if (autoinit)
  85.       printf("Auto-initialized\n");
  86.     else
  87.       printf("Single-cycle\n");
  88.  
  89.     if (!init_xms())
  90.       {
  91.         printf("ERROR:  Can not initialize extended memory\n");
  92.         printf("HIMEM.SYS must be installed\n");
  93.         exit(EXIT_FAILURE);
  94.       }
  95.     else
  96.       {
  97.         printf("Extended memory successfully initialized\n");
  98.         printf("Free XMS memory: %uk    ", getfreexms());
  99.         if (!getfreexms())
  100.           {
  101.             printf("ERROR:  Insufficient free XMS\n");
  102.             exit(EXIT_FAILURE);
  103.           }
  104.         else
  105.           {
  106.             printf("Loading sounds\n");
  107. #ifdef SHAREDEMB
  108.             init_sharing();
  109. #endif
  110.             for (i=0; i < NUMSOUNDS; i++)
  111.               load_sound(&(sound[i]), soundfile[i]);
  112.             atexit(ourexitproc);
  113.  
  114.           }
  115.       }
  116.     init_mixing();
  117.     printf("\n");
  118.   }
  119.  
  120. void shutdown(void)
  121.   {
  122.     int i;
  123.  
  124.     shutdown_mixing();
  125.     shutdown_sb();
  126.  
  127.     for (i=0; i < NUMSOUNDS; i++)
  128.       free_sound(sound+i);
  129. #ifdef SHAREDEMB
  130.     shutdown_sharing();
  131. #endif
  132.     printf("\n");
  133.   }
  134.  
  135. int main(void)
  136.   {
  137.     init();
  138.  
  139.     start_sound(sound[0], 0, ON); /* Start up the jet engine */
  140.  
  141.     printf("Press:\n");
  142.     printf("  1)  Machine Gun\n");
  143.     printf("  2)  Crash\n");
  144.     printf("  3)  Cannon\n");
  145.     printf("  4)  Laser\n");
  146.     printf("  5)  Breaking glass\n");
  147.     printf("  Q)  Quit\n");
  148.  
  149.     stop = FALSE;
  150.  
  151.     counter = 0;
  152.  
  153.     do
  154.       {
  155.        /* Increment and display counters */
  156.         counter++;
  157.         cprintf("%8lu %8lu %4u", counter, intcount, voicecount);
  158.         gotoxy(1, wherey());
  159.  
  160.        /* Maybe start a random sound */
  161.         if (!random(10000))
  162.           {
  163.            num = (random(NUMSOUNDS-1))+1;
  164.            start_sound(sound[num], num, OFF);
  165.           }
  166.  
  167.        /* Start a sound if a key is pressed */
  168.         if (kbhit())
  169.           {
  170.             inkey = getch();
  171.             if ((inkey >= '0') && (inkey <= '9'))
  172.               {
  173.                 num = inkey - '0'; /* Convert to integer */
  174.                 if (num < NUMSOUNDS)
  175.                   start_sound(sound[num], num, FALSE);
  176.               }
  177.             else
  178.               stop = TRUE;
  179.           }
  180.       }
  181.     while (!stop);
  182.  
  183.     printf("\n");
  184.     stop_sound(1); /* Stop the jet engine */
  185.  
  186.     shutdown();
  187.  
  188.     return(EXIT_SUCCESS);
  189.   }
  190.